<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/struts-tags.tld" prefix="s"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>喜乐康智能家居系统</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
  	<script type="text/javascript">
  	var rightAddDeviceId = 0;
  	var pressRightClass;
  	var isOpen = '0';
  	var level = '0';
  	function sceneDeviceListDown(upDown){
  		var top = $(".setting_scene_right_detail_left_list").position().top;
		var height = $(".setting_scene_right_detail_left_list").height();
		if((top + height) > 300){
			if(upDown == 'down'){
				$(".setting_scene_right_detail_left_down").css("background-image","url('"+evn_Path+"resource/down_press_s.png')");
			}
			if(upDown == 'up'){
				
			//	alert("top:" + top + "\r\nheight:"+height);
				top-=10;
				$(".setting_scene_right_detail_left_list").css("top",top+"px");
				$(".setting_scene_right_detail_left_down").css("background-image","url('"+evn_Path+"resource/down_s.png')");
	  	  	}
		}
  	  	
	}

  	function sceneDeviceListUp(upDown){
  		var top = $(".setting_scene_right_detail_left_list").position().top;
		var height = $(".setting_scene_right_detail_left_list").height();
		if((top + height) < height){
			if(upDown == 'down'){
				$(".setting_scene_right_detail_left_up").css("background-image","url('"+evn_Path+"resource/up_press_s.png')");
			}
			if(upDown == 'up'){
				
			//	alert("top:" + top + "\r\nheight:"+height);
				top+=10;
				$(".setting_scene_right_detail_left_list").css("top",top+"px");
				$(".setting_scene_right_detail_left_up").css("background-image","url('"+evn_Path+"resource/up_s.png')");
	  	  	}
		}
  	  	
	}

  	function pressRightDevice(deviceId,deviceType){
  		var className = $("#right_scene_device_list_img_li"+deviceId).attr("className");
  		if(rightAddDeviceId!=0){
  			$("#right_scene_device_list_img_li"+rightAddDeviceId).attr("className",pressRightClass);
  		}
  		pressRightClass = className;
  		rightAddDeviceId = deviceId;
  		if(className.indexOf("device_use_img_li_on_off") != -1){
  			$("#right_scene_device_list_img_li"+deviceId).attr("className","device_use_img_li_on_off_press_s");
  		}else if(className.indexOf("device_use_img_li_turn") != -1){
  			$("#right_scene_device_list_img_li"+deviceId).attr("className","device_use_img_li_turn_press_s");
  		}else if(className.indexOf("device_use_img_li_socket") != -1){
  			$("#right_scene_device_list_img_li"+deviceId).attr("className","device_use_img_li_socket_press_s");
  		}
  		isOpen = $("#right_scene_device_list_img_li"+deviceId).attr("isOpen");
  		level = $("#right_scene_device_list_img_li"+deviceId).attr("level");
  		if(deviceType != 2){
  			$(".device_use_content_bottom_level").css("visibility","hidden");
  		}else{
  			$(".device_use_content_bottom_level").css("visibility","");
  		}
  		settingSceneIsOpen(isOpen,level);
  		
//  		alert("isOpen:"+isOpen+"\r\nlevel:"+level);
  	}

  	function operateLevel(operlevel){
  		if(rightAddDeviceId==0){
  			alert("请选择面板！");
  			return ;
  		}
  		if(operlevel > 0){
  			isOpenOper = '1';
  			$(".setting_scene_open").css("background-image","url('"+evn_Path+"resource/setting_scene_button_press.png')");
  			$(".setting_scene_close").css("background-image","url('"+evn_Path+"resource/setting_scene_button.png')");
  	  		
  		}else{
  			isOpenOper = '0';
  			$(".setting_scene_open").css("background-image","url('"+evn_Path+"resource/setting_scene_button.png')");
  			$(".setting_scene_close").css("background-image","url('"+evn_Path+"resource/setting_scene_button_press.png')");
  	  	}
  		switch(operlevel){
  			case '0':{
  				$(".device_use_content_bottom_level_1").css("background-image","");
  				$(".device_use_content_bottom_level_2").css("background-image","");
  				$(".device_use_content_bottom_level_3").css("background-image","");
  				$(".device_use_content_bottom_level_4").css("background-image","");
  				$(".device_use_content_bottom_level_5").css("background-image","");
  				$(".device_use_content_bottom_level_6").css("background-image","");
  				$(".device_use_content_bottom_level_7").css("background-image","");
  				break;
  			}
  			case '1':{
  				$(".device_use_content_bottom_level_1").css("background-image","url('"+evn_Path+"resource/device_level_1.png')");
  				$(".device_use_content_bottom_level_2").css("background-image","");
  				$(".device_use_content_bottom_level_3").css("background-image","");
  				$(".device_use_content_bottom_level_4").css("background-image","");
  				$(".device_use_content_bottom_level_5").css("background-image","");
  				$(".device_use_content_bottom_level_6").css("background-image","");
  				$(".device_use_content_bottom_level_7").css("background-image","");
  				break;
  			}
  			case '2':{
  				$(".device_use_content_bottom_level_1").css("background-image","url('"+evn_Path+"resource/device_level_1.png')");
  				$(".device_use_content_bottom_level_2").css("background-image","url('"+evn_Path+"resource/device_level_2.png')");
  				$(".device_use_content_bottom_level_3").css("background-image","");
  				$(".device_use_content_bottom_level_4").css("background-image","");
  				$(".device_use_content_bottom_level_5").css("background-image","");
  				$(".device_use_content_bottom_level_6").css("background-image","");
  				$(".device_use_content_bottom_level_7").css("background-image","");
  				break;
  			}
  			case '3':{
  				$(".device_use_content_bottom_level_1").css("background-image","url('"+evn_Path+"resource/device_level_1.png')");
  				$(".device_use_content_bottom_level_2").css("background-image","url('"+evn_Path+"resource/device_level_2.png')");
  				$(".device_use_content_bottom_level_3").css("background-image","url('"+evn_Path+"resource/device_level_3.png')");
  				$(".device_use_content_bottom_level_4").css("background-image","");
  				$(".device_use_content_bottom_level_5").css("background-image","");
  				$(".device_use_content_bottom_level_6").css("background-image","");
  				$(".device_use_content_bottom_level_7").css("background-image","");
  				break;
  			}
  			case '4':{
  				$(".device_use_content_bottom_level_1").css("background-image","url('"+evn_Path+"resource/device_level_1.png')");
  				$(".device_use_content_bottom_level_2").css("background-image","url('"+evn_Path+"resource/device_level_2.png')");
  				$(".device_use_content_bottom_level_3").css("background-image","url('"+evn_Path+"resource/device_level_3.png')");
  				$(".device_use_content_bottom_level_4").css("background-image","url('"+evn_Path+"resource/device_level_4.png')");
  				$(".device_use_content_bottom_level_5").css("background-image","");
  				$(".device_use_content_bottom_level_6").css("background-image","");
  				$(".device_use_content_bottom_level_7").css("background-image","");
  				break;
  			}
  			case '5':{
  				$(".device_use_content_bottom_level_1").css("background-image","url('"+evn_Path+"resource/device_level_1.png')");
  				$(".device_use_content_bottom_level_2").css("background-image","url('"+evn_Path+"resource/device_level_2.png')");
  				$(".device_use_content_bottom_level_3").css("background-image","url('"+evn_Path+"resource/device_level_3.png')");
  				$(".device_use_content_bottom_level_4").css("background-image","url('"+evn_Path+"resource/device_level_4.png')");
  				$(".device_use_content_bottom_level_5").css("background-image","url('"+evn_Path+"resource/device_level_5.png')");
  				$(".device_use_content_bottom_level_6").css("background-image","");
  				$(".device_use_content_bottom_level_7").css("background-image","");
  				break;
  			}
  			case '6':{
  				$(".device_use_content_bottom_level_1").css("background-image","url('"+evn_Path+"resource/device_level_1.png')");
  				$(".device_use_content_bottom_level_2").css("background-image","url('"+evn_Path+"resource/device_level_2.png')");
  				$(".device_use_content_bottom_level_3").css("background-image","url('"+evn_Path+"resource/device_level_3.png')");
  				$(".device_use_content_bottom_level_4").css("background-image","url('"+evn_Path+"resource/device_level_4.png')");
  				$(".device_use_content_bottom_level_5").css("background-image","url('"+evn_Path+"resource/device_level_5.png')");
  				$(".device_use_content_bottom_level_6").css("background-image","url('"+evn_Path+"resource/device_level_6.png')");
  				$(".device_use_content_bottom_level_7").css("background-image","");
  				break;
  			}
  			case '7':{
  				$(".device_use_content_bottom_level_1").css("background-image","url('"+evn_Path+"resource/device_level_1.png')");
  				$(".device_use_content_bottom_level_2").css("background-image","url('"+evn_Path+"resource/device_level_2.png')");
  				$(".device_use_content_bottom_level_3").css("background-image","url('"+evn_Path+"resource/device_level_3.png')");
  				$(".device_use_content_bottom_level_4").css("background-image","url('"+evn_Path+"resource/device_level_4.png')");
  				$(".device_use_content_bottom_level_5").css("background-image","url('"+evn_Path+"resource/device_level_5.png')");
  				$(".device_use_content_bottom_level_6").css("background-image","url('"+evn_Path+"resource/device_level_6.png')");
  				$(".device_use_content_bottom_level_7").css("background-image","url('"+evn_Path+"resource/device_level_7.png')");
  				break;
  			}
  		}
  		if(pressRightClass.indexOf("device_use_img_li_on_off") != -1){
  	  		if(operlevel > 0){
  	  			pressRightClass = "device_use_img_li_on_off_open_s";
  	  	  	}else{
  	  	  		pressRightClass = "device_use_img_li_on_off_s";
  	  	  	}
  		}else if(pressRightClass.indexOf("device_use_img_li_turn") != -1){
  			if(operlevel > 0){
  	  			pressRightClass = "device_use_img_li_turn_open_s";
  	  	  	}else{
  	  	  		pressRightClass = "device_use_img_li_turn_s";
  	  	  	}
  		}else if(pressRightClass.indexOf("device_use_img_li_socket") != -1){
  			if(operlevel > 0){
  	  			pressRightClass = "device_use_img_li_socket_open_s";
  	  	  	}else{
  	  	  		pressRightClass = "device_use_img_li_socket_s";
  	  	  	}
  		}

  		$("#right_scene_device_list_img_li"+rightAddDeviceId).attr("level",operlevel);
  		level = operlevel;
  		if(operlevel > 0){
  			isOpen = 1;
  		}else{
  			isOpen = 0;
  		}
  		$("#right_scene_device_list_img_li"+rightAddDeviceId).attr("isOpen",isOpen);
  	}

  	function settingSceneIsOpen(isOpenOper,openLevel){
  		if(rightAddDeviceId==0){
  			alert("请选择面板！");
  			return ;
  		}
  		level = openLevel;
  		if(isOpenOper == '1'){
  			$(".setting_scene_open").css("background-image","url('"+evn_Path+"resource/setting_scene_button_press.png')");
  			$(".setting_scene_close").css("background-image","url('"+evn_Path+"resource/setting_scene_button.png')");
  			
  		}else{
  			$(".setting_scene_open").css("background-image","url('"+evn_Path+"resource/setting_scene_button.png')");
  			$(".setting_scene_close").css("background-image","url('"+evn_Path+"resource/setting_scene_button_press.png')");
  		}
  		if(pressRightClass.indexOf("device_use_img_li_on_off") != -1){
  	  		if(level > 0){
  	  			pressRightClass = "device_use_img_li_on_off_open_s";
  	  	  	}else{
  	  	  		pressRightClass = "device_use_img_li_on_off_s";
  	  	  	}
  		}else if(pressRightClass.indexOf("device_use_img_li_turn") != -1){
  			if(level > 0){
  	  			pressRightClass = "device_use_img_li_turn_open_s";
  	  	  	}else{
  	  	  		pressRightClass = "device_use_img_li_turn_s";
  	  	  	}
  		}else if(pressRightClass.indexOf("device_use_img_li_socket") != -1){
  			if(level > 0){
  	  			pressRightClass = "device_use_img_li_socket_open_s";
  	  	  	}else{
  	  	  		pressRightClass = "device_use_img_li_socket_s";
  	  	  	}
  		}
  		
  		isOpen = isOpenOper;
  		operateLevel(level);
  	}


	function settingSceneSave(upDown){
		var sceneName =  $("#sceneName").val();
		if(sceneName == null ||  $("#sceneName").val().trim()==""){
			if(upDown=='down'){
				alert("场景名称不能为空！");
			}
			
			return ;
		}
		if(sceneName.length > 20){
			if(upDown=='down'){
				alert("场景名称不能大于20字符！");
				var f = document.getElementById("sceneName");
				window.setTimeout(function(){f.focus();f.select(); }, 0);
			}
			return ;
		}
		if(upDown == 'down'){
			$(".setting_scene_save").css("background-image","url('"+evn_Path+"resource/setting_scene_save_press.png')");
		}else if(upDown == 'up'){
		
			$.post("setting!checkSceneName.do",{'sceneName':sceneName},function(data){
	  			if(data=='success'){
	  				saveSceneSuccess( upDown);
	  			}else{
	  				var d = data.split(",");
	  				if(d.length > 1 && currentSceneId == d[1]){
	  						saveSceneSuccess( upDown);
	  				}else{
	  					alert("场景名称已存在！");
	  				}
	  				
	  			}
	  		});
		
			$(".setting_scene_save").css("background-image","url('"+evn_Path+"resource/setting_scene_save.png')");
		}
	}
	
	function saveSceneSuccess(upDown){
		var arrayObj = new Array();
			$("[name='sceneDeviceListName']").each(
						function(){
						//	alert($(this).text());
							arrayObj.push({
								"deviceId":$(this).attr("deviceId"),
								"isOpen":$(this).attr("isOpen"),
								"level":$(this).attr("level")
							});
						}
					);
			var sceneDeviceA = new SceneDeviceAll();
			sceneDeviceA.sceneId = currentSceneId;
			sceneDeviceA.sceneName = $("#sceneName").val();
			sceneDeviceA.deviceList = arrayObj;
			$.ajax({type:'post',
				 url:'<%=basePath%>setting!saveSceneDevice.do',  
				 data:{jsonData:escape($.toJSON(sceneDeviceA))},
				 success:function(data){
					if(data=='success'){
						alert("保存成功！");
						$('.setting_background').load('setting!scene.do');
					}else{
						alert("保存失败！");
					}
				 }
				}); 
			
	}

	function settingSceneDeviceListDelete(upDown){
		if(rightAddDeviceId==0){
			if(upDown == 'down'){
  				alert("请选择面板！");
			}
  			return ;
  		}else{
			if(upDown == 'down'){
				$(".setting_scene_device_list_delete").css("background-image","url('"+evn_Path+"resource/setting_scene_button_press.png')");
			}else if(upDown == 'up'){
				$("#right_scene_device_list_img_li"+rightAddDeviceId).remove();
				rightAddDeviceId = 0;
				$(".setting_scene_close").css("background-image","url('"+evn_Path+"resource/setting_scene_button.png')");
				$(".setting_scene_open").css("background-image","url('"+evn_Path+"resource/setting_scene_button.png')");
				$(".device_use_content_bottom_level").css("visibility","hidden");
				$(".setting_scene_device_list_delete").css("background-image","url('"+evn_Path+"resource/setting_scene_button.png')");
			}
  	  	}
	}
  	
  	</script>
  	
  </head>
  
  <body>
  	<div class="setting_scene_right_detail">
  		<div class="setting_scene_right_detail_left">
  			<div class="setting_scene_right_detail_left_list">
  				<s:iterator value="roomList" id="room">
  					<div class="setting_scene_detail" id="setting_scene_detail_room<s:property value="roomId"/>">
  						<div style="width: 50px;float:left;font-size: 13px;font-weight: bold;margin-top: 5px;"><s:property value="roomName"/></div>
  						<div style="width: 240px;float:left;margin-left: 5px;" id="setting_scene_detail_deviceList<s:property value="roomId"/>">
  							<s:iterator id="device" value="deviceList" status="status">
  								<div name="sceneDeviceListName" deviceId="<s:property value="deviceId"/>" onclick="pressRightDevice(<s:property value="deviceId"/>,<s:property value="deviceType"/>)" isOpen="<s:property value="isOpen"/>" level="<s:property value="level"/>"  id="right_scene_device_list_img_li<s:property value="deviceId"/>" 
									
									<s:if test="deviceType==1 && isOpen == 1">
					   					class="device_use_img_li_on_off_open_s"
					   				</s:if>	
					   				<s:elseif test="deviceType==1 && isOpen == 0">
										class="device_use_img_li_on_off_s"
									</s:elseif>
									<s:elseif test="deviceType==2 && isOpen == 1">
										class="device_use_img_li_turn_open_s"
									</s:elseif>
									<s:elseif test="deviceType==2 && isOpen == 0">
										class="device_use_img_li_turn_s"
									</s:elseif>
					   				<s:elseif test="deviceType==3 && isOpen == 1">
										class="device_use_img_li_socket_open_s"
									</s:elseif>	
									<s:elseif test="deviceType==3 && isOpen == 0">
										class="device_use_img_li_socket_s"
									</s:elseif>	
									
								
									
									style="position: relative;margin-bottom:12px;font-size:12px;"
									
									><s:property value="deviceName"/>
								</div>
  							</s:iterator>
  						</div>
  						<div class="clear"></div>
  					</div>
  				</s:iterator>
  			</div>
  			
  		</div>
  		<div class="setting_scene_right_detail_left_up_down">
  			<div class="setting_scene_right_detail_left_up" onmousedown="sceneDeviceListUp('down')" onmouseup="sceneDeviceListUp('up')"></div>
  			<div class="setting_scene_right_detail_left_down" onmousedown="sceneDeviceListDown('down')" onmouseup="sceneDeviceListDown('up')"></div>
  		</div>
  	</div>
	<div class="setting_scene_right_status">
		<div class="setting_scene_open_close">
			<div class="setting_scene_open" onclick="settingSceneIsOpen('1','7')">开</div>
			<div class="setting_scene_close" onclick="settingSceneIsOpen('0','0')">关</div>
			<div class="setting_scene_device_list_delete" onmousedown="settingSceneDeviceListDelete('down')" onmouseup="settingSceneDeviceListDelete('up')">删除</div>
			
		</div>
		<div class="device_use_content_bottom_level" style="margin-left: 5px;">
			<div onclick="operateLevel('1')" class="device_use_content_bottom_level_1"></div>
			<div onclick="operateLevel('2')" class="device_use_content_bottom_level_2"></div>
			<div onclick="operateLevel('3')" class="device_use_content_bottom_level_3"></div>
			<div onclick="operateLevel('4')" class="device_use_content_bottom_level_4"></div>
			<div onclick="operateLevel('5')" class="device_use_content_bottom_level_5"></div>
			<div onclick="operateLevel('6')" class="device_use_content_bottom_level_6"></div>
			<div onclick="operateLevel('7')" class="device_use_content_bottom_level_7"></div>
		</div>
		<div class="setting_scene_save" onmousedown="settingSceneSave('down')" onmouseup="settingSceneSave('up')"></div>
  	</div>
  </body>
</html>
